import os, sys, cv2
from base64 import b64decode, b64encode
import numpy as np
from typing import Dict

parent_path = os.path.abspath(os.path.join(__file__, *(['..'] * 5)))
sys.path.insert(0, parent_path)

from core.task.modules.processors.base_processor import BaseProcessor

class BaseReturn(BaseProcessor):
    def __init__(self, keys, BaseReturn_keys = []) -> None:
        super().__init__(keys)
        self.return_keys = BaseReturn_keys

    def _init_check(self):
        pass

    def _call(self, data: Dict) -> Dict:
        return_json = {}
        for key_ in self.return_keys:
            data_ = data[key_]
            data_ = serialization(data_)
            return_json[key_] = data_
        data[self.keys["out"]] = return_json
        return data
    
def serialization(data):
    if isinstance(data,dict):
        for key,value in data.items():
            data[key] = serialization(value)
        return data
    elif isinstance(data, np.ndarray):
        return data.astype(np.float64).tolist()
    else:
        return data

    
